package Relatorios;
import java.io.File;  
import java.io.FileInputStream;  
import java.io.FileNotFoundException;  
import java.io.FileOutputStream;   
import java.io.IOException;   
import java.io.OutputStream;

import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.filechooser.FileNameExtensionFilter;

import org.apache.poi.hssf.*;  
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
  
 

public abstract class Excel {

	protected final int LINHA_FIXA = 0;
	protected final int COLUNA_FIXA =0;
	protected final int ROW =1;
	protected final int COLUMN =0;
	protected HSSFWorkbook workbook;
	protected HSSFSheet planilha;
	protected HSSFRow row;	
	protected HSSFCellStyle estilo;
	protected HSSFCell celulaData;
	
	public abstract void geraRelatorio() throws IOException;	
	
	public FileOutputStream geraArquivo(){
		
		FileOutputStream arquivo = null;
		//fileSeparator
		String diretorioBase = System.getProperty("user.home")+ "/Desktop";
		
		String nomeArquivo = "";
		File dir = new File(diretorioBase);
		
		JFileChooser chooser = new JFileChooser();
		chooser.setCurrentDirectory(dir);
		chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
		
		FileNameExtensionFilter filtro = new FileNameExtensionFilter("Arquivos Excel (.xls)","xls"); 
		
		chooser.setAcceptAllFileFilterUsed(false);
		chooser.addChoosableFileFilter(filtro);
		
		int retorno = chooser.showOpenDialog(null);
		
		if(retorno == JFileChooser.APPROVE_OPTION){
			nomeArquivo = chooser.getSelectedFile().getAbsolutePath()+".xls";
			try {
				arquivo = new FileOutputStream(nomeArquivo);
				JOptionPane.showMessageDialog(null, "O arquivo " + nomeArquivo + " foi salvo com sucesso");
			} catch (FileNotFoundException e) {
				
				e.printStackTrace();
			}		
		}else{
			return null;
		}
		
		
		return arquivo;
		
		
	}
}
